package com.jin.controller;

import com.jin.config.MessageConfig.Message;
import com.jin.pojo.UserInfo;
import com.jin.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户模块")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;


    @ApiOperation(value = "添加用户")
    @PostMapping("/insertUser")
    public Message insertUser(UserInfo userInfo){
//        System.out.println(userInfo.getUserId());
//        System.out.println(userInfo.getUserName());
        return userInfoService.insertUserInfo(userInfo)>0?Message.success("成功").add("success"):Message.fail("失败").add("fail");
    }

    @ApiOperation(value = "根据id删除用户")
    @DeleteMapping("/delUserById")
    public Message delUserById(Integer userId){
        return userInfoService.delUserById(userId)>0?Message.success("200").add("success"):Message.fail("400").add("fail");
    }

    @ApiOperation(value = "根据id修改用户")
    @PutMapping("/updateUser")
    public Message updateUser(UserInfo userInfo){
        return userInfoService.updateUserInfo(userInfo)>0?Message.success("200").add("success"):Message.fail("400").add("fail");
    }

    @ApiOperation(value = "查找全部用户")
    @GetMapping("/selectUser")
    public Message selectUser() {
        return Message.success("200").add(userInfoService.selectUser());
    }

    @ApiOperation(value ="查询用户的信息还有对应的用户等级")
    @GetMapping("/selectUserInfoLevel")
    public Message selectUserInfoLevel(Integer userId) {
        return Message.success("200").add(userInfoService.selectUserInfoLevel(userId));
    }

    @ApiOperation(value ="登录用户")
    @PostMapping("/loginUser")
    public Message loginUser(String userAccount, String userPassword) {
        return Message.success("200").add(userInfoService.loginUser(userAccount,userPassword),20000);
    }

}
